{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'令诩'"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = '令诩'\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(str, 2)"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a), len(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(b'\\xe4\\xbb\\xa4\\xe8\\xaf\\xa9', bytes, 6)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create Byte instance of Unicode String (Non-ASCII Character)\n",
    "b = a.encode('utf-8')\n",
    "b, type(b), len(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(228, 187, 164)"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b[0], b[1], b[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(b'\\xe4', b'\\xbb', b'\\xa4\\xe8\\xaf\\xa9')"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b[:1], b[1:2], b[2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "uni = u'python'\n",
    "type(uni)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create byte instance of ASCII string\n",
    "asc = 'python'\n",
    "asc_byte = b'python'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(str, bytes)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(asc), type(asc_byte)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('p', 112)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "asc[0], asc_byte[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "UnicodeDecodeError",
     "evalue": "'big5' codec can't decode byte 0xa4 in position 2: incomplete multibyte sequence",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mUnicodeDecodeError\u001b[0m                        Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-41-46746d3e22cc>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'令'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mname_en\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'utf-8'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mname_de\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mname_en\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'big5'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m \u001b[0mname_de\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mUnicodeDecodeError\u001b[0m: 'big5' codec can't decode byte 0xa4 in position 2: incomplete multibyte sequence"
     ]
    }
   ],
   "source": [
    "name = ''\n",
    "name_en = name.encode('utf-8')\n",
    "name_de = name_en.decode('big5')\n",
    "name_de"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 进制转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "decimal = 100\n",
    "binary = 0b11111111\n",
    "hexi = 0xFFFF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(255, 65535)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# To DEC\n",
    "int(binary), int(hexi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('0b1100100', '0b1111111111111111')"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# To BIN\n",
    "bin(decimal), bin(hexi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('0x64', '0xff')"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# To HEX\n",
    "hex(decimal), hex(binary)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "诩\n"
     ]
    }
   ],
   "source": [
    "a = '\\u8be9'\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 进入正题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def sigmoid(x):\n",
    "    return 1/(1+np.exp(-x))\n",
    "\n",
    "# Network size\n",
    "N_input = 4\n",
    "N_hidden = 3\n",
    "N_output = 2\n",
    "\n",
    "np.random.seed(42)\n",
    "# Make some fake data\n",
    "X = np.random.randn(4).reshape(4, 1)\n",
    "\n",
    "weights_input_to_hidden = np.random.normal(0, scale=0.1, size=(N_input, N_hidden))\n",
    "weights_hidden_to_output = np.random.normal(0, scale=0.1, size=(N_hidden, N_output))\n",
    "\n",
    "# print X.shape\n",
    "# print weights_input_to_hidden.shape\n",
    "# print weights_hidden_to_output.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hidden-layer Output:\n",
      "[[ 0.41492192]\n",
      " [ 0.42604313]\n",
      " [ 0.5002434 ]]\n",
      "Output-layer Output:\n",
      "[[ 0.49815196]\n",
      " [ 0.48539772]]\n"
     ]
    }
   ],
   "source": [
    "# TODO: Make a forward pass through the network\n",
    "\n",
    "hidden_layer_in = np.dot(weights_input_to_hidden.T, X)\n",
    "hidden_layer_out = sigmoid(hidden_layer_in)\n",
    "\n",
    "print('Hidden-layer Output:')\n",
    "print(hidden_layer_out)\n",
    "\n",
    "output_layer_in = np.dot(weights_hidden_to_output.T, hidden_layer_out)\n",
    "output_layer_out = sigmoid(output_layer_in)\n",
    "\n",
    "print('Output-layer Output:')\n",
    "print(output_layer_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD3CAYAAAAALt/WAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl01Od97/H3LJoZjfZltCIEEtKD2MEYgzdMvGAwNg62\n4zhptsZJ3aZNG997e9repb3n9LT3njZp2rRumjTJbZJ6wQtesAPGLF7AmB2EQY+QhCS07+uMZjQz\nv/uHBFZsQAIkjX4z39c5OqOZ32j0ffQbffTT83t+z2MxDAMhhBDmZY10AUIIIW6MBLkQQpicBLkQ\nQpicBLkQQpicBLkQQpicfbq/YXt7vymHyaSluenu9ka6jGkVa22OtfaCtNlMPJ4ky5W2yRH5BNnt\ntkiXMO1irc2x1l6QNkcLCXIhhDA5CXIhhDA5CXIhhDA5CXIhhDC5CQW5UuoWpdS+yzz+oFLqsFLq\nQ6XUtya9OiGEEOMaN8iVUn8K/Dvg+tTjccA/APcBa4FvK6Wyp6JIIYQQVzaRI/JqYMtlHi8DqrTW\n3VrrAPABcOdkFieEEGJ8414QpLV+WSk15zKbkoHeMff7gZTxXi8tzW3acZweT1KkS5h2sdbmWGsv\nSJtvxHAwjHdomEHfMAO+kdvBoWG8Q0GG/EF8gSC+oSBDgRDBUJjP3zWPfE/ipHzvsW7kys4+YOxP\nIwnoGe+LzHhFFYzs+Pb2/kiXMa1irc2x1l6QNo81HAzR7x2mzxsYuR0cue33Bi495h0K4vUH8Q4N\n4/UHCQ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H/Ofq5hZHF02PB3wM/\nBpoiXchkkq6Vy1BKfRP43qcergOe11qfVEpFoKqpc4X2fkNrfXh0ge1fA38y/ZVNm6stZxiVtNYD\nAEqpJOAl4H9EtqKpp5T6OtCutd6plPrzSNczmWSulQkaXVi6YfTuauCQ1jqyq0FPMaXUYuB54L9q\nrX8T6XqmilLqB8BBrfXW0fsNWutZES5ryimlChhZOOYZrfXPI13PVFNKvQcYox/LgErgIa11S0QL\nmwRyRD5BWut5Fz9XStUC90WsmGmglFrAyL/fj2utT0a6nim2H3gQ2HqZ5QyjklIqG3gb+EOt9e5I\n1zMdxh54KaX2AU9FQ4iDBLm4sr8FXMA/jnYl9WqtN0e2pCnzmeUMI1zPdPgLIA34n0qpi33lG7TW\nUXUSMFZI14oQQpicjFoRQgiTkyAXQgiTkyAXQgiTkyAXQgiTkyAXQgiTkyAXQgiTkyAXQgiT+//B\nZsDUS87sTwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xa906690>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.arange(-5, 5, 0.0001)\n",
    "y = 1/(1 + np.exp(-x))\n",
    "y_prime = 1/(1 + np.exp(-x)) - 1/(1 + np.exp(-x))**2\n",
    "plt.plot(x, y)\n",
    "plt.plot(x, y_prime)\n",
    "plt.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import MinMaxScaler\n",
    "import numpy as np\n",
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input\n",
      "[[[[1 2 1]\n",
      "   [4 2 3]\n",
      "   [1 3 5]\n",
      "   [4 2 4]]\n",
      "\n",
      "  [[1 3 2]\n",
      "   [3 1 4]\n",
      "   [3 5 3]\n",
      "   [5 1 1]]\n",
      "\n",
      "  [[5 1 5]\n",
      "   [1 2 3]\n",
      "   [3 2 5]\n",
      "   [5 1 3]]\n",
      "\n",
      "  [[4 3 2]\n",
      "   [5 5 4]\n",
      "   [5 4 2]\n",
      "   [1 2 4]]]]\n",
      "kernel\n",
      "[[[[5 4 5 4 1]\n",
      "   [2 4 1 2 1]\n",
      "   [1 5 4 5 2]]\n",
      "\n",
      "  [[5 4 1 5 5]\n",
      "   [2 4 4 5 1]\n",
      "   [3 4 4 2 4]]]\n",
      "\n",
      "\n",
      " [[[1 5 1 1 4]\n",
      "   [2 5 4 5 1]\n",
      "   [3 3 1 3 2]]\n",
      "\n",
      "  [[2 2 3 4 3]\n",
      "   [5 4 4 1 5]\n",
      "   [4 1 2 2 5]]]]\n"
     ]
    }
   ],
   "source": [
    "data = np.random.rand(48) * 5\n",
    "data = np.ceil(data).astype(int)\n",
    "data = data.reshape(1, 4, 4, 3)\n",
    "print(\"input\")\n",
    "print(data)\n",
    "\n",
    "w = np.random.rand(12 * 5) * 5\n",
    "w = np.ceil(w).astype(int)\n",
    "w = w.reshape(2, 2, 3, 5)\n",
    "print(\"kernel\")\n",
    "print(w)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[[3, 1, 5],\n",
       "         [4, 3, 5]],\n",
       "\n",
       "        [[1, 2, 1],\n",
       "         [1, 3, 5]]]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[3, 1, 5],\n",
       "        [4, 3, 5]],\n",
       "\n",
       "       [[1, 2, 1],\n",
       "        [1, 3, 5]]])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[0, :, :, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[5, 2, 1],\n",
       "        [5, 2, 3]],\n",
       "\n",
       "       [[1, 2, 3],\n",
       "        [2, 5, 4]]])"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w[:, :, :, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[[  83.   93.   71.   92.   84.]\n",
      "   [  93.  145.  103.  133.  100.]]\n",
      "\n",
      "  [[ 117.  148.  128.  126.  118.]\n",
      "   [ 107.  146.  100.  122.  114.]]]]\n",
      "(1, 2, 2, 5)\n"
     ]
    }
   ],
   "source": [
    "input = tf.placeholder(tf.float32, (None, 4, 4, 3))\n",
    "filter_weights = tf.placeholder(tf.float32, (2, 2, 3, 5)) # (height, width, input_depth, output_depth)\n",
    "strides = [1, 2, 2, 1] # (batch, height, width, depth)\n",
    "padding = 'VALID'\n",
    "conv = tf.nn.conv2d(input, filter_weights, strides, padding)\n",
    "\n",
    "with tf.Session() as s:\n",
    "    res = s.run(conv, feed_dict={input:data, filter_weights:w})\n",
    "    print(res)\n",
    "    print(res.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "119\n"
     ]
    }
   ],
   "source": [
    "with tf.Session() as s:\n",
    "    print(s.run(tf.reduce_sum(tf.multiply(w[:,:,:,0], data))))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[[ 3.21678114]\n",
      "   [ 6.24559164]\n",
      "   [ 5.32314157]\n",
      "   [ 7.29637003]]\n",
      "\n",
      "  [[ 1.34117866]\n",
      "   [ 3.99991059]\n",
      "   [ 6.04236889]\n",
      "   [ 6.98537636]]\n",
      "\n",
      "  [[ 3.37499952]\n",
      "   [ 3.21826577]\n",
      "   [ 2.59558773]\n",
      "   [ 4.48323584]]\n",
      "\n",
      "  [[ 5.85446501]\n",
      "   [ 5.8771534 ]\n",
      "   [ 7.19603539]\n",
      "   [ 5.25111914]]]]\n",
      "[[[[ 5.51404667]\n",
      "   [ 4.92545509]]\n",
      "\n",
      "  [[ 6.00410557]\n",
      "   [ 8.06925297]]]]\n"
     ]
    }
   ],
   "source": [
    "# pic = np.array([[4, 5, 10, 22], [9, 3, 14, 3], [2, 5, 7, 9], [11, 3, 5, 0]])\n",
    "pic = tf.truncated_normal([1, 4, 4, 1], mean=5, stddev=2)\n",
    "output = tf.nn.max_pool(pic, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')\n",
    "\n",
    "with tf.Session() as s:\n",
    "    s.run(tf.global_variables_initializer())\n",
    "    print(pic.eval())\n",
    "    print(s.run(output))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import math\n",
    "i = np.arange(299)\n",
    "p = 1.0/384\n",
    "trial = 300\n",
    "prob = []\n",
    "for x in i:\n",
    "    prob.append(math.factorial(x) / math.factorial(x) * math.factorial(trial - x) * p**x * (1 - p)**(trial - x))\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "plt.plot(x, prob)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 测试滤波器对图像的影响"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 测试 TensorBoard"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "a = tf.constant(2, name=\"a\")\n",
    "b = tf.constant(3, name=\"b\")\n",
    "x = tf.add(a, b, name=\"add\")\n",
    "with tf.Session() as sess:\n",
    "    writer = tf.summary.FileWriter('./graphs', sess.graph)\n",
    "    sess.run(x)\n",
    "writer.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 空间维度的探索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 3])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "np.random.randint(10, size=(2,))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 4],\n",
       "       [8, 1, 8]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(10, size=(2, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[3, 4, 5, 7],\n",
       "        [0, 1, 6, 3],\n",
       "        [9, 4, 7, 2]],\n",
       "\n",
       "       [[5, 2, 1, 0],\n",
       "        [6, 5, 3, 0],\n",
       "        [8, 8, 9, 3]]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(10, size=(2, 3, 4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[[5, 0, 5, 9, 4],\n",
       "         [9, 6, 3, 1, 7],\n",
       "         [1, 7, 2, 8, 1],\n",
       "         [6, 0, 4, 3, 1]],\n",
       "\n",
       "        [[0, 4, 2, 1, 7],\n",
       "         [9, 9, 1, 0, 1],\n",
       "         [8, 6, 5, 6, 7],\n",
       "         [4, 5, 2, 7, 8]],\n",
       "\n",
       "        [[5, 5, 4, 6, 9],\n",
       "         [7, 3, 2, 0, 3],\n",
       "         [6, 3, 3, 1, 0],\n",
       "         [9, 9, 9, 5, 2]]],\n",
       "\n",
       "\n",
       "       [[[2, 4, 9, 9, 5],\n",
       "         [0, 8, 9, 1, 4],\n",
       "         [4, 1, 2, 1, 3],\n",
       "         [1, 6, 5, 8, 2]],\n",
       "\n",
       "        [[5, 7, 8, 1, 6],\n",
       "         [9, 8, 0, 0, 9],\n",
       "         [1, 1, 9, 7, 1],\n",
       "         [0, 6, 8, 0, 6]],\n",
       "\n",
       "        [[4, 4, 5, 6, 4],\n",
       "         [0, 1, 4, 8, 0],\n",
       "         [3, 5, 3, 0, 2],\n",
       "         [4, 9, 3, 5, 5]]]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(10, size=(2, 3, 4, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[[[3, 6],\n",
       "          [0, 3],\n",
       "          [9, 6]],\n",
       "\n",
       "         [[6, 4],\n",
       "          [9, 2],\n",
       "          [8, 2]],\n",
       "\n",
       "         [[1, 9],\n",
       "          [5, 4],\n",
       "          [5, 3]],\n",
       "\n",
       "         [[0, 0],\n",
       "          [0, 4],\n",
       "          [1, 4]]],\n",
       "\n",
       "\n",
       "        [[[5, 0],\n",
       "          [6, 1],\n",
       "          [8, 9]],\n",
       "\n",
       "         [[7, 3],\n",
       "          [0, 9],\n",
       "          [0, 3]],\n",
       "\n",
       "         [[4, 5],\n",
       "          [2, 4],\n",
       "          [2, 1]],\n",
       "\n",
       "         [[7, 5],\n",
       "          [6, 7],\n",
       "          [2, 5]]],\n",
       "\n",
       "\n",
       "        [[[8, 6],\n",
       "          [6, 7],\n",
       "          [2, 6]],\n",
       "\n",
       "         [[7, 0],\n",
       "          [4, 5],\n",
       "          [3, 8]],\n",
       "\n",
       "         [[5, 5],\n",
       "          [1, 0],\n",
       "          [4, 9]],\n",
       "\n",
       "         [[8, 4],\n",
       "          [3, 3],\n",
       "          [2, 2]]],\n",
       "\n",
       "\n",
       "        [[[4, 8],\n",
       "          [5, 9],\n",
       "          [3, 8]],\n",
       "\n",
       "         [[3, 0],\n",
       "          [9, 0],\n",
       "          [8, 1]],\n",
       "\n",
       "         [[4, 7],\n",
       "          [9, 1],\n",
       "          [3, 9]],\n",
       "\n",
       "         [[1, 9],\n",
       "          [8, 7],\n",
       "          [5, 1]]],\n",
       "\n",
       "\n",
       "        [[[0, 8],\n",
       "          [2, 7],\n",
       "          [0, 2]],\n",
       "\n",
       "         [[9, 2],\n",
       "          [8, 2],\n",
       "          [0, 9]],\n",
       "\n",
       "         [[0, 1],\n",
       "          [3, 5],\n",
       "          [4, 9]],\n",
       "\n",
       "         [[3, 7],\n",
       "          [1, 3],\n",
       "          [6, 3]]]],\n",
       "\n",
       "\n",
       "\n",
       "       [[[[8, 0],\n",
       "          [7, 9],\n",
       "          [1, 5]],\n",
       "\n",
       "         [[4, 3],\n",
       "          [2, 7],\n",
       "          [3, 4]],\n",
       "\n",
       "         [[3, 3],\n",
       "          [2, 4],\n",
       "          [3, 3]],\n",
       "\n",
       "         [[5, 1],\n",
       "          [6, 5],\n",
       "          [5, 5]]],\n",
       "\n",
       "\n",
       "        [[[1, 6],\n",
       "          [6, 8],\n",
       "          [7, 6]],\n",
       "\n",
       "         [[4, 1],\n",
       "          [6, 4],\n",
       "          [2, 6]],\n",
       "\n",
       "         [[8, 7],\n",
       "          [5, 2],\n",
       "          [0, 2]],\n",
       "\n",
       "         [[5, 2],\n",
       "          [0, 2],\n",
       "          [8, 6]]],\n",
       "\n",
       "\n",
       "        [[[2, 2],\n",
       "          [4, 7],\n",
       "          [5, 2]],\n",
       "\n",
       "         [[6, 8],\n",
       "          [4, 9],\n",
       "          [8, 1]],\n",
       "\n",
       "         [[8, 5],\n",
       "          [2, 7],\n",
       "          [3, 4]],\n",
       "\n",
       "         [[0, 7],\n",
       "          [5, 0],\n",
       "          [5, 8]]],\n",
       "\n",
       "\n",
       "        [[[3, 4],\n",
       "          [8, 5],\n",
       "          [7, 5]],\n",
       "\n",
       "         [[4, 2],\n",
       "          [3, 0],\n",
       "          [4, 2]],\n",
       "\n",
       "         [[8, 9],\n",
       "          [8, 3],\n",
       "          [6, 7]],\n",
       "\n",
       "         [[2, 4],\n",
       "          [7, 1],\n",
       "          [3, 5]]],\n",
       "\n",
       "\n",
       "        [[[6, 3],\n",
       "          [7, 6],\n",
       "          [8, 2]],\n",
       "\n",
       "         [[3, 2],\n",
       "          [9, 2],\n",
       "          [8, 7]],\n",
       "\n",
       "         [[4, 2],\n",
       "          [8, 6],\n",
       "          [8, 8]],\n",
       "\n",
       "         [[4, 4],\n",
       "          [6, 8],\n",
       "          [4, 4]]]],\n",
       "\n",
       "\n",
       "\n",
       "       [[[[2, 2],\n",
       "          [5, 0],\n",
       "          [9, 5]],\n",
       "\n",
       "         [[9, 6],\n",
       "          [1, 5],\n",
       "          [8, 7]],\n",
       "\n",
       "         [[1, 2],\n",
       "          [8, 4],\n",
       "          [1, 4]],\n",
       "\n",
       "         [[5, 3],\n",
       "          [4, 6],\n",
       "          [4, 8]]],\n",
       "\n",
       "\n",
       "        [[[2, 2],\n",
       "          [6, 9],\n",
       "          [9, 9]],\n",
       "\n",
       "         [[2, 7],\n",
       "          [9, 6],\n",
       "          [6, 7]],\n",
       "\n",
       "         [[0, 9],\n",
       "          [8, 1],\n",
       "          [9, 3]],\n",
       "\n",
       "         [[5, 5],\n",
       "          [7, 6],\n",
       "          [2, 2]]],\n",
       "\n",
       "\n",
       "        [[[7, 0],\n",
       "          [5, 1],\n",
       "          [6, 1]],\n",
       "\n",
       "         [[9, 5],\n",
       "          [0, 3],\n",
       "          [5, 6]],\n",
       "\n",
       "         [[5, 5],\n",
       "          [2, 7],\n",
       "          [0, 9]],\n",
       "\n",
       "         [[7, 5],\n",
       "          [7, 7],\n",
       "          [0, 8]]],\n",
       "\n",
       "\n",
       "        [[[8, 2],\n",
       "          [8, 2],\n",
       "          [4, 0]],\n",
       "\n",
       "         [[3, 1],\n",
       "          [1, 8],\n",
       "          [2, 4]],\n",
       "\n",
       "         [[9, 9],\n",
       "          [6, 1],\n",
       "          [0, 0]],\n",
       "\n",
       "         [[7, 4],\n",
       "          [4, 5],\n",
       "          [4, 6]]],\n",
       "\n",
       "\n",
       "        [[[7, 6],\n",
       "          [2, 4],\n",
       "          [1, 5]],\n",
       "\n",
       "         [[7, 2],\n",
       "          [3, 0],\n",
       "          [1, 0]],\n",
       "\n",
       "         [[8, 7],\n",
       "          [3, 3],\n",
       "          [9, 4]],\n",
       "\n",
       "         [[6, 0],\n",
       "          [4, 5],\n",
       "          [4, 8]]]],\n",
       "\n",
       "\n",
       "\n",
       "       [[[[3, 7],\n",
       "          [0, 7],\n",
       "          [4, 0]],\n",
       "\n",
       "         [[6, 2],\n",
       "          [1, 5],\n",
       "          [2, 0]],\n",
       "\n",
       "         [[9, 0],\n",
       "          [7, 6],\n",
       "          [1, 2]],\n",
       "\n",
       "         [[9, 8],\n",
       "          [5, 3],\n",
       "          [5, 4]]],\n",
       "\n",
       "\n",
       "        [[[0, 1],\n",
       "          [6, 4],\n",
       "          [5, 1]],\n",
       "\n",
       "         [[7, 1],\n",
       "          [9, 2],\n",
       "          [3, 4]],\n",
       "\n",
       "         [[9, 6],\n",
       "          [1, 3],\n",
       "          [6, 2]],\n",
       "\n",
       "         [[9, 9],\n",
       "          [3, 2],\n",
       "          [5, 7]]],\n",
       "\n",
       "\n",
       "        [[[7, 7],\n",
       "          [8, 3],\n",
       "          [7, 7]],\n",
       "\n",
       "         [[5, 8],\n",
       "          [0, 1],\n",
       "          [1, 0]],\n",
       "\n",
       "         [[6, 3],\n",
       "          [6, 8],\n",
       "          [8, 7]],\n",
       "\n",
       "         [[1, 5],\n",
       "          [9, 9],\n",
       "          [4, 6]]],\n",
       "\n",
       "\n",
       "        [[[4, 8],\n",
       "          [7, 3],\n",
       "          [8, 5]],\n",
       "\n",
       "         [[5, 5],\n",
       "          [3, 0],\n",
       "          [8, 1]],\n",
       "\n",
       "         [[7, 7],\n",
       "          [8, 0],\n",
       "          [6, 5]],\n",
       "\n",
       "         [[3, 5],\n",
       "          [5, 1],\n",
       "          [6, 4]]],\n",
       "\n",
       "\n",
       "        [[[9, 9],\n",
       "          [3, 8],\n",
       "          [4, 6]],\n",
       "\n",
       "         [[3, 9],\n",
       "          [8, 8],\n",
       "          [7, 3]],\n",
       "\n",
       "         [[3, 0],\n",
       "          [1, 4],\n",
       "          [5, 0]],\n",
       "\n",
       "         [[5, 4],\n",
       "          [8, 9],\n",
       "          [1, 2]]]],\n",
       "\n",
       "\n",
       "\n",
       "       [[[[0, 3],\n",
       "          [1, 1],\n",
       "          [6, 6]],\n",
       "\n",
       "         [[2, 1],\n",
       "          [1, 1],\n",
       "          [8, 1]],\n",
       "\n",
       "         [[6, 3],\n",
       "          [4, 8],\n",
       "          [1, 8]],\n",
       "\n",
       "         [[1, 2],\n",
       "          [4, 2],\n",
       "          [2, 1]]],\n",
       "\n",
       "\n",
       "        [[[0, 1],\n",
       "          [4, 7],\n",
       "          [7, 7]],\n",
       "\n",
       "         [[4, 7],\n",
       "          [9, 2],\n",
       "          [8, 7]],\n",
       "\n",
       "         [[5, 7],\n",
       "          [3, 2],\n",
       "          [9, 2]],\n",
       "\n",
       "         [[9, 7],\n",
       "          [4, 7],\n",
       "          [1, 0]]],\n",
       "\n",
       "\n",
       "        [[[4, 3],\n",
       "          [3, 5],\n",
       "          [9, 3]],\n",
       "\n",
       "         [[0, 8],\n",
       "          [8, 1],\n",
       "          [2, 5]],\n",
       "\n",
       "         [[4, 7],\n",
       "          [3, 6],\n",
       "          [0, 6]],\n",
       "\n",
       "         [[7, 5],\n",
       "          [4, 5],\n",
       "          [5, 2]]],\n",
       "\n",
       "\n",
       "        [[[1, 6],\n",
       "          [1, 0],\n",
       "          [0, 5]],\n",
       "\n",
       "         [[4, 8],\n",
       "          [0, 3],\n",
       "          [3, 5]],\n",
       "\n",
       "         [[8, 9],\n",
       "          [2, 0],\n",
       "          [7, 3]],\n",
       "\n",
       "         [[0, 0],\n",
       "          [3, 6],\n",
       "          [2, 0]]],\n",
       "\n",
       "\n",
       "        [[[8, 5],\n",
       "          [0, 4],\n",
       "          [9, 2]],\n",
       "\n",
       "         [[2, 6],\n",
       "          [6, 3],\n",
       "          [2, 1]],\n",
       "\n",
       "         [[5, 4],\n",
       "          [3, 4],\n",
       "          [6, 6]],\n",
       "\n",
       "         [[3, 6],\n",
       "          [9, 0],\n",
       "          [9, 6]]]],\n",
       "\n",
       "\n",
       "\n",
       "       [[[[5, 6],\n",
       "          [7, 2],\n",
       "          [6, 3]],\n",
       "\n",
       "         [[0, 8],\n",
       "          [5, 4],\n",
       "          [6, 1]],\n",
       "\n",
       "         [[4, 3],\n",
       "          [8, 0],\n",
       "          [1, 6]],\n",
       "\n",
       "         [[8, 2],\n",
       "          [2, 3],\n",
       "          [5, 7]]],\n",
       "\n",
       "\n",
       "        [[[3, 6],\n",
       "          [0, 0],\n",
       "          [7, 7]],\n",
       "\n",
       "         [[4, 2],\n",
       "          [0, 6],\n",
       "          [0, 0]],\n",
       "\n",
       "         [[1, 9],\n",
       "          [7, 4],\n",
       "          [2, 6]],\n",
       "\n",
       "         [[0, 6],\n",
       "          [4, 5],\n",
       "          [4, 1]]],\n",
       "\n",
       "\n",
       "        [[[3, 7],\n",
       "          [8, 3],\n",
       "          [1, 4]],\n",
       "\n",
       "         [[6, 4],\n",
       "          [8, 4],\n",
       "          [4, 2]],\n",
       "\n",
       "         [[8, 6],\n",
       "          [4, 1],\n",
       "          [2, 2]],\n",
       "\n",
       "         [[2, 4],\n",
       "          [6, 1],\n",
       "          [9, 4]]],\n",
       "\n",
       "\n",
       "        [[[9, 6],\n",
       "          [4, 8],\n",
       "          [3, 7]],\n",
       "\n",
       "         [[5, 6],\n",
       "          [2, 6],\n",
       "          [4, 4]],\n",
       "\n",
       "         [[0, 7],\n",
       "          [0, 6],\n",
       "          [2, 7]],\n",
       "\n",
       "         [[5, 4],\n",
       "          [5, 0],\n",
       "          [5, 7]]],\n",
       "\n",
       "\n",
       "        [[[2, 9],\n",
       "          [5, 1],\n",
       "          [9, 6]],\n",
       "\n",
       "         [[7, 9],\n",
       "          [5, 2],\n",
       "          [6, 1]],\n",
       "\n",
       "         [[9, 6],\n",
       "          [4, 6],\n",
       "          [2, 8]],\n",
       "\n",
       "         [[4, 4],\n",
       "          [3, 2],\n",
       "          [4, 4]]]]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(10, size=(6, 5, 4, 3, 2))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
